package ar.com.utn.openqsb.commons.util;

import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.jvnet.substance.skin.SubstanceOfficeSilver2007LookAndFeel;

/**
 * Some generic functions.
 * 
 * @author rvega
 * 
 */
public class Utility {

	/**
	 * Configure look and feel using Substance.
	 * 
	 * @throws UnsupportedLookAndFeelException
	 *             if substance is not in the classpath.
	 */
	public static void configureUI() throws UnsupportedLookAndFeelException {
		UIManager.setLookAndFeel(new SubstanceOfficeSilver2007LookAndFeel());
		JFrame.setDefaultLookAndFeelDecorated(true);
		JDialog.setDefaultLookAndFeelDecorated(true);
	}

	/**
	 * build an icon from the classpath.
	 * 
	 * @param iconName
	 *            path to the icon to build.
	 * @return an Icon object or null if iconName can not be found.
	 */
	public static ImageIcon getIcon(String iconName) {
		ClassLoader cl = Thread.currentThread().getContextClassLoader();
		URL url = cl.getResource(iconName);
		if (url != null)
			return new ImageIcon(url);
		return null;
	}

}
